<template>
    <!-- <div class="wrapper">
        <el-card class="from-content" shadow="never"> </el-card>
        <div class="detail_footer"></div>
    </div> -->
    <div class="container_box">
        <el-scrollbar class="main_box">
            <div class="lbs_carte_box">
                <BasicConfig ref="BasicConfigRef" class="from_basic_config__card" :group_id="0" />
            </div>
        </el-scrollbar>
        <div class="footer_box">
            <el-button @click="goBack">取消</el-button>
            <el-button v-if="isNotCreate" type="primary" @click="onSubmit">保存</el-button>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted, computed, provide, nextTick, reactive, onBeforeMount } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';
import { useStore } from '@/store';
import { toCreateLbs, toEditLbs, showLbsInfo } from '@/api/customer/groupManage/lbspullgroup';

// 组件
import BasicConfig from './components/BasicConfig.vue';

const store = useStore();

const router = useRouter();
const route = useRoute();
const goBack = () => {
    router.back();
};
const isNotCreate = route.query.type !== 'detail';
const onSubmit = async () => {
    const isEdit = route.query.type === 'edit';
    const baseInfo = await validatorHandle[1]();
    const params = {
        id: isEdit ? route.query.id : undefined,
        ...baseInfo
    };
    store.dispatch('setGroupId', params.group_id);
    const res = await (isEdit ? toEditLbs(params) : toCreateLbs(params));
    ElMessage.success(isEdit ? '编辑成功' : '新增成功');
    router.push({
        path: '/customer/groupManage/lbspullgroup',
        query: {
            group_id: params.group_id
        }
    });
};
const validatorHandle = {};

const BasicConfigRef = ref();
// 表单配置-标题
const basicInfo = computed(() => BasicConfigRef.value?.formData);
provide('basicInfo', basicInfo);

const initDetailInfo = async () => {
    if (!['edit', 'detail'].includes(`${route.query.type}`)) return;
    const res = await showLbsInfo({
        id: route.query.id
    });
    BasicConfigRef.value.setDetailInfo(res);
};

onBeforeMount(() => {
    initDetailInfo();
});
// 查看活动
onMounted(() => {
    validatorHandle[1] = BasicConfigRef.value.getParams;
});
</script>

<style scoped lang="scss">
.lbs_carte_box {
    padding: 24px;
}
</style>
